package com.secxiot.consumer.user.controller;

import com.secxiot.common.entity.ResultVo;
import com.secxiot.consumer.user.feign.UserClient;
import com.secxiot.provider.user.entity.SysExchangeRecord;
import com.secxiot.provider.user.entity.SysExchangeRules;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户积分模块")
@RequestMapping("/integral")
@RestController
public class IntegralController {

    @Autowired
    private UserClient userClient;

    @ApiOperation(value = "积分兑换规则", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Long")
    })
    @PostMapping("/getExchangeRules")
    public ResultVo<List<SysExchangeRules>> getExchangeRules(@RequestParam(value = "userId", required = true) Long userId) {
        return new ResultVo<List<SysExchangeRules>>(userClient.getExchangeRules(userId));
    }

    @ApiOperation(value = "积分兑换", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "integralNum", value = "积分数量", paramType = "form", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "exchangeRulesId", value = "兑换规则ID", paramType = "form", required = true, dataType = "Long")
    })
    @PostMapping("/exchange")
    public ResultVo<Integer> integralExchange(@RequestParam(value = "userId", required = true) Long userId,
                                              @RequestParam(value = "integralNum", required = true) Long integralNum,
                                              @RequestParam(value = "exchangeRulesId", required = true) Long exchangeRulesId) {
        Integer integer = userClient.integralExchange(userId, integralNum, exchangeRulesId);
        return new ResultVo<Integer>(integer);
    }

    @ApiOperation(value = "获取兑换记录", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "pageSize", value = "条数", required = true, paramType = "query", dataType = "Long")
    })
    @GetMapping("/getExchangeRecordList")
    public ResultVo<List<SysExchangeRecord>> getExchangeRecordList(
            @RequestParam(value = "userId", required = true) Long userId,
            @RequestParam(value = "pageNo", required = true) Long pageNo,
            @RequestParam(value = "pageSize", required = true) Long pageSize) {
        return new ResultVo<List<SysExchangeRecord>>(userClient.getExchangeRecordList(userId, pageNo, pageSize));
    }
}
